<%@page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@include file="/common/definition.jsp"%>

<html:html>
<tiles:insert beanName="admin-definition" flush="true">
	<tiles:put name="title"> Administrator Management </tiles:put>
	<tiles:put name="body" type="string">
	<div class="mainHome" style="padding-top: 15px; min-height: 360px">
	<div class="row col-md-12">
		<s:form theme="simple">
			<div class="col-md-4" style="padding-top: 10px;">
				<div class="muted h3" style="padding-bottom: 15px;">Thương Hiệu</div>
				<ul
					style="width: 200px; height: 200px; overflow: auto; border: 1px solid #90bade;">
						<s:iterator value="listBrandInfo" id="list">
							<li><s:a action="viewBrand">
									<s:property value="brandName" />
									<s:param name="id" value="brandID" />
								</s:a></li>
						</s:iterator>
				</ul>
			</div>
		</s:form>
		<s:form name="addBrand" id="add-brand" theme="simple" cssClass="form">
			<div class="col-md-5" style="padding-bottom: 15px;">
				<div class="muted h3" style="padding-bottom: 10px;">Thêm thương hiệu</div>
				<div class="col-sm-12" style="padding: 0px;">
					<div class="error_box"></div>
				</div>
				<s:if test="errorAddBrand == null || errorAddBrand == ''">
				</s:if>
				<s:elseif test="errorAddBrand != null">
					<div class="error_box" style="display: block;"><s:property value="errorAddBrand" /></div>
				</s:elseif>
				<div class="form-group">
					<label>Tên hãng sản xuất</label> <input type="text"
						data-toggle="tooltip" 
						title="Tên hãng sản xuất có độ dài từ 2 đến 20 ký tự"
						name="brandInfo.brandName" class="form-control" />
					<%-- <s:textfield name="brandInfo.brandName"
										cssClass="contact_input" /> --%>
				</div>
				<br />
				<div class="form-group">
					<label>Website</label> 
					<input type="text" name="brandInfo.website"
						data-toggle="tooltip" 
						title="website của hãng sản xuất."
						class="form-control" />
					<%-- <s:textfield name="brandInfo.website" cssClass="contact_input" /> --%>
				</div>
				<br />
				<div>
					<button onclick="switchAction('add-brand', 'addBrand')"
						class="btn btn-primary">Thêm</button>
					<button type="reset" class="btn btn-default">Nhập lại</button>
				</div>
			</div>
		</s:form>
		<script type="text/javascript">
		var validator = new FormValidator('addBrand', 
		[{
			name: 'brandInfo.brandName',  
			display: 'tên hãng sản xuất',
			rules: 'required|min_length[2]|max_length[20]'
		},{
			name: 'brandInfo.website',  
			display: 'website',
			rules: 'required'
		}], function(errors, evt) {
					var SELECTOR_ERRORS = $('.error_box'),
					SELECTOR_SUCCESS = $('.success_box');
					
				if (errors.length > 0) {
					SELECTOR_ERRORS.empty();
					for (var i = 0, errorLength = errors.length; i < errorLength; i++) {
						SELECTOR_ERRORS.append(errors[i].message + '<br />');
					}
					
					SELECTOR_SUCCESS.css({ display: 'none' });
					SELECTOR_ERRORS.fadeIn(200);
				} else {
					SELECTOR_ERRORS.css({ display: 'none' });
					SELECTOR_SUCCESS.fadeIn(200);
				}			
			});
		</script>
	</div>
	</div>
	</tiles:put>
</tiles:insert>
</html:html>

<script type="text/javascript">
	function switchAction(formId, action) {
		$('#' + formId).attr('action', action);
		$.post(action);
	}
</script>
